//
//  ViewController.m
//  SHWheel
//
//  Created by YYKJ on 2020/7/20.
//  Copyright © 2020 YYKJ. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController.h"
#import "SHLayoutButton.h"
#import "YYSliderCaptchaView.h"

#import "SHCommonDefines.h"
//#import "QMUICommonDefines.h"
#import <Masonry/Masonry.h>
#import "XXExtension.h"
#import "SHUIHelper.h"

@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) NSArray *items;
@property (nonatomic, strong) UIWindow *testWindow;
@property (nonatomic, strong) UITableView *tableView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"SHWheel";
    self.navigationController.navigationBar.translucent = NO;
    [self setUpUI];
    [self test];
}

- (void)test {
    NSString *price = @"92.739999999999995";
    NSNumber *number = [NSNumber numberWithString:price];
    NSString *convertString = [NSString decimalStringWithString:price];
    
    NSLog(@"number = %@, convertString = %@", number, convertString);
}

- (void)layoutButton {
    /**
     *
     */
    SHLayoutButton *button = [SHLayoutButton buttonWithType:UIButtonTypeCustom];
    button.backgroundColor = UIColor.greenColor;
    button.spacingBetweenImageAndTitle = 4;
    button.imagePosition = SHButtonImagePositionLeft;
    [button setImage:[UIImage imageNamed:@"Common_tab_Shopping_s"] forState:UIControlStateNormal];
    [button setTitle:@"购物" forState:UIControlStateNormal];
    [button setTitleColor:UIColor.redColor forState:UIControlStateNormal];
    [self.view addSubview:button];
    
    button.frame = CGRectMake(0, 0, 80, 80);
    
//    [button mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(50);
//        make.leading.mas_equalTo(0);
//        make.width.mas_equalTo(90);
//        make.height.mas_equalTo(80);
//    }];
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    
}

- (void)setUpUI {
    CGFloat height = SCREEN_HEIGHT - NavigationBarHeight - StatusBarHeightConstant;
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, height) style:UITableViewStyleGrouped];
    tableView.rowHeight = 40;
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.tableFooterView = UIView.new;
    [tableView registerClass:UITableViewCell.class forCellReuseIdentifier:@"cellId"];
    [self.view addSubview:tableView];
    
    [self layoutButton];
}

- (IBAction)captchaViewClick:(id)sender {
    CGFloat captchaWidth = 233;
    CGFloat captchaHeight = 226;
    YYSliderCaptchaView *captchaView = [[YYSliderCaptchaView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - captchaWidth)/2, (SCREEN_HEIGHT - captchaHeight)/2, captchaWidth, captchaHeight) image:[UIImage imageNamed:@"2.jpg"]];
    [captchaView showAnimation:YES];
    captchaView.identifierCheckCompletion = ^(BOOL isSuccess) {
        if (isSuccess) {
            
        } else {
            
        }
    };
}

- (IBAction)imagePickerClick:(id)sender {}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.items.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.text = self.items[indexPath.row][0];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSString *title = self.items[indexPath.row][0];
    NSString *targetVCName = self.items[indexPath.row][1];
    if (![NSString isEmpty:targetVCName]) {
        UIViewController *targetVC = [NSClassFromString(targetVCName) new];
        targetVC.title = title;
        [self.navigationController pushViewController:targetVC animated:YES];
    } else {
        [self localHandle:title];
    }
}

- (void)localHandle:(NSString *)targetName {
    if ([targetName isEqualToString:@"CaptchaView"]) {
        [self captchaViewClick:nil];
    } else if ([targetName isEqualToString:@"ImagePicker"]) {
        // TODO:Dush
    }
}

#pragma mark - Getter
- (NSArray *)items {
    if (!_items) {
        _items = @[@[@"Alert", @"SHAlertTableVC"],
                   @[@"CaptchaView", @""],
                   @[@"CarouseView", @"SHCarouseVC"],
                   @[@"ImagePicker", @""],
                   @[@"Search", @"SHSearchViewController"],
                   @[@"DailView", @"DailViewController"],
                   @[@"CornerRadius", @"CornerRadiusViewController"],
                   @[@"Countdown by pop", @"CountDownViewController"]];
    }
    return  _items;
}

@end
